package com.newangels.action;

import com.newangels.service.AgentManagerService;
import com.newangels.service.impl.AgentManagerServiceImpl;
import net.sf.json.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;

/**
 * 删除Agent
 *
 * @author: TangLiang
 * @date: 2020/5/22 10:08
 * @since: 1.0
 */
@WebServlet("/deleteAgent")
public class deleteAgentServlet extends HttpServlet {

    AgentManagerService agentManagerService = AgentManagerServiceImpl.getAgentManagerServiceImpl();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/plain");
        String[] agentList = request.getParameterValues("AGENT_LIST");
        JSONObject jsonObject = new JSONObject();
        if (agentManagerService.deleteAgentList(Arrays.asList(agentList)) == agentList.length) {
            jsonObject.put("success", true);
        } else {
            jsonObject.put("success", false);
        }
        response.getWriter().write(jsonObject.toString());
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
